<template>
  <div class="ry-perList">
    <!-- 顶部搜索 -->
    <div class="head">
      <el-form :inline="true" :model="workSearchForm" class="demo-form-inline">
        <el-form-item label="人员搜索：">
          <el-input
            v-model="workSearchForm.userName"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item label="角色：">
          <el-select v-model="workSearchForm.roleName" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search" icon="el-icon-search"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 顶部搜索 -->

    <!-- 列表区域 -->
    <div class="body">
      <!-- 新建按钮 -->
      <el-button icon="el-icon-circle-plus-outline" @click="isShow = true"
        >新建</el-button
      >
      <!-- 新建按钮 -->

      <!-- 列表 -->
      <div class="list">
        <el-table :data="workList" style="width: 100%">
          <el-table-column prop="num" label="序号" width="80" type="index">
          </el-table-column>
          <el-table-column prop="userName" label="人员名称" width="160">
          </el-table-column>
          <el-table-column prop="roleName" label="角色" width="180">
          </el-table-column>
          <el-table-column prop="mobile" label="联系电话" width="180">
          </el-table-column>
          <el-table-column
            prop="workCount"
            label="完成工单（本月）"
            width="180"
          >
          </el-table-column>
          <el-table-column prop="progressTotal" label="进行中工单" width="180">
          </el-table-column>
          <el-table-column prop="total" label="拒绝工单（本月）" width="180">
          </el-table-column>
          <el-table-column prop="handle" label="操作">
            <template slot-scope="scope">
              <a
                href="javascript:;"
                class="detail"
                @click="getDetail(scope.row.id)"
                >查看详情</a
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 列表 -->
    </div>
    <!-- 列表区域 -->

    <!-- 底部 -->
    <div class="foot">
      <span
        >共{{ totalCount }}条记录 第 {{ pageIndex }}/{{ totalPage }} 页</span
      >
      <div class="but">
        <el-button @click="prePage" :disabled="preBtn">上一页</el-button>
        <el-button @click="nextPage" :disabled="nextBtn">下一页</el-button>
      </div>
    </div>
    <!-- 底部 -->
    <addPerson :isShow="isShow" @close="closeFn"></addPerson>
  </div>
</template>

<script>
import addPerson from './components/addPerson'
import { getWork, getHoleWork } from '@/api/person'
export default {
  components: {
    addPerson
  },
  data () {
    return {
      isShow: false,
      preBtn: false,
      nextBtn: false,
      totalCount: '',
      totalPage: '',
      pageIndex: 1,
      holeWorkList: [],
      workList: [
        {
          num: '',
          userName: '',
          roleName: '',
          mobile: '',
          total: '',
          progressTotal: '',
          workCount: ''
        }
      ],
      options: [
        { value: '运营员', label: '运营员' },
        { value: '维修员', label: '维修员' }
      ],
      workSearchForm: {
        userName: '',
        roleName: ''
      }
    }
  },
  methods: {
    // *获取工作量列表
    async getWork () {
      const { data } = await getWork(this.pageIndex)
      // console.log(data)
      this.workList = data.currentPageRecords
      this.totalCount = data.totalCount
      this.totalPage = data.totalPage
      if (this.pageIndex <= 1) {
        this.preBtn = true
      } else {
        this.preBtn = false
      }
      if (this.pageIndex >= this.totalPage) {
        this.nextBtn = true
      } else {
        this.nextBtn = false
      }
    },
    // 顶部搜索框
    search () {
      // 当搜索框内容不为空时，查找名字中包含此字符串
      if (this.workSearchForm) {
        this.workList = this.holeWorkList.filter((item) => {
          return item.roleName.includes(this.workSearchForm.roleName) &&
          item.userName.includes(this.workSearchForm.userName)
        })
      } else {
        this.getWork()
      }
      this.workSearchForm.userName = ''
      this.workSearchForm.roleName = ''
    },
    // 底部按钮下一页
    nextPage () {
      this.pageIndex++
      this.getWork()
    },
    // 底部按钮上一页
    prePage () {
      this.pageIndex--
      this.getWork()
    },
    // 关闭弹出框
    closeFn (status) {
      this.isShow = status
    },
    getDetail (id) {
      console.log(id)
    }
  },
  async created () {
    this.getWork()
    const { data } = await getHoleWork()
    // console.log(data.currentPageRecords)
    this.holeWorkList = data.currentPageRecords
  }
}
</script>

<style lang="scss" scoped>
.ry-perList {
  background-color: #f8fafd;
  padding-top: 80px;
  padding-left: 20px;
  .head {
    background-color: #fff;
    width: 100%;
    height: 60px;
    padding-left: 20px;
    padding-top: 10px;
  }
  .body {
    margin-top: 20px;
    width: 100%;
    background-color: #fff;
    padding-left: 20px;
    padding-top: 20px;
    .el-button {
      color: #fff;
      background-color: #ff6927;
      margin-bottom: 20px;
    }
    .list {
      ::v-deep .el-table th {
        background-color: #f3f6fb;
      }
      .detail {
        color: blue;
      }
    }
  }
  .foot {
    width: 100%;
    height: 120px;
    line-height: 60px;
    background-color: #fff;
    padding-left: 30px;
    padding-right: 80px;
    display: flex;
    justify-content: space-between;
    span {
      color: #d8dfe5;
      font-size: 16px;
    }
    .el-button {
      background-color: #d5ddf8;
    }
  }
}
</style>
